#pragma once
#include"noncopyable.h"
#include"Timestamp.h"
#include<vector>
#include<unordered_map>
class Channel;
class Eventloop;

class Poller:noncopyable
{
    public:
        using ChannelList=std::vector<Channel*>;

        Poller(Eventloop *loop);
        virtual ~Poller()=default;
        //给所有I/O复用保留统一的接口
        virtual Timestamp poll(int timeoutMs,ChannelList *activeChannels)=0;
        virtual void updateChannel(Channel *channel)=0;
        virtual void removeChannel(Channel *channnel)=0; 

        //判断参数channel是否在当前Poller当中
        bool hasChannel(Channel *channel) const;
        //事件循环可以通过当前接口获取默认的I/O复用的具体实现
        static Poller* newDefaultPoller(Eventloop *loop);
    protected:
        //这里map的key就是sockfd value就是sockfd所属的通道类型channel
        using ChannelMap=std::unordered_map<int,Channel*>;
        ChannelMap Channels_;
    private:
        Eventloop *ownerLoop_;//定义poller所属的事件循环EventLoop
};